package gouhuo.allbugs.top.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.HashSet;

/**
 * 自定义 Swagger 接口文档的配置
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        HashSet<String> strings = new HashSet<>();
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo())
                //设置返回数据类型
                .produces(strings)
                //分组名称
                .groupName("2.0")
                .select()
                //这里指定扫描包路径
                .apis(RequestHandlerSelectors.basePackage("gouhuo.allbugs.top.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo buildApiInfo() {
        Contact contact = new Contact("小智", "", "");
        return new ApiInfoBuilder()
                .title("篝火APP")
                .description("篝火项目接口文档")
                .contact(contact)
                .version("2.0")
                .build();
    }
}
